package com.erclab.internal.xpresso.util;

import java.util.HashMap;

import com.erclab.internal.xpresso.forms.Form;
import com.erclab.internal.xpresso.reports.Report;

public class ExceptionUtil {

	public static String getSecurityExceptionString(Form theForm){
		StringBuffer result = new StringBuffer(); 
		result.append("<resource>" + 
		theForm.getFormName() + ".form?action=" + 
		theForm.getFormParameters().getAction());
		
		String uniqueKeyValue = theForm.getFormParameters().getUniqueKeyValue();
		if (uniqueKeyValue != null){
			result.append("&uniqueKeyValue=" + uniqueKeyValue); 
		}
		
		HashMap<String, String> params = theForm.getFormParameters().getRequestParameters();
		for (String key:params.keySet()){
			String value = params.get( key );
			result.append("&" + key + "=" + value);
		}
		
		
		result.append("</resource><user>" +
		theForm.getFormParameters().getUser().getNetId() + "</user>");
		return result.toString();
	}
	
	public static String getSecurityExceptionString(Report theReport){
		return theReport.getReportName() + ".report?uniqueKeyValue=" + 
			theReport.getReportParameters().getUniqueKeyValue() +
			theReport.getReportParameters().getUser().getNetId();
	}
	
	public static String getResource(String e){
		return e.substring(e.indexOf("<resource>") + 10,  e.indexOf("</resource>"));
	}
	
}
